package FileIO.ReaderWriter;


import FileIO.Student;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

public class useBufferedWriter {
    public static void main(String[] args) throws IOException {
        List<Student> studentList = Arrays.asList(new Student[] {
                new Student("张三", 18, 80.9d),
                new Student("王五", 20, 67.5d)
        });
        writeStudents(studentList);
    }

    public static void writeStudents(List<Student> studentList) throws IOException {
        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new FileWriter("src/main/data/students.txt"));
            for (Student s: studentList) {
                writer.write(s.getName() + ", " + s.getAge() + ", " + s.getScore());
                writer.newLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            writer.close();
        }
    }
}
